#include <iostream>
#include "SGL.h"

using namespace std;
using namespace SGLEngine;

using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;

class CSquare : public CObject2D {
	public:
		CSquare()
		{
			
		}
};

class MoveSquare : public SGLAction {
	public:
		MoveSquare()
		{

		}
		virtual void Action(const irr::SEvent& irrevent, SGL* engine)
		{
			if (irrevent.KeyInput.Key == irr::KEY_DOWN && irrevent.KeyInput.PressedDown)
			{
				engine->get2DObject("cs1")->Move(1,0);
			}
			if (irrevent.KeyInput.Key == irr::KEY_UP && irrevent.KeyInput.PressedDown)
			{
				engine->get2DObject("cs1")->Move(0,1);
			}
			cout << irrevent.KeyInput.Key << endl;
		}
};

start()
{
	SGLSettings set;
	set.DriverType = irr::video::EDT_OPENGL;
	SGL engine(set);
	//irr::video::ED
	CSquare * csquare1;
	csquare1 = new CSquare();
	csquare1->addLine(vector2di(1,1), vector2di(1,100), engine.getSGLColor()->DARK_GREEN);
	csquare1->addLine(vector2di(1,100), vector2di(100,100), engine.getSGLColor()->DARK_GREEN);
	csquare1->addLine(vector2di(100,100), vector2di(100,1), engine.getSGLColor()->DARK_GREEN);
	csquare1->addLine(vector2di(100,1), vector2di(1,1), engine.getSGLColor()->DARK_GREEN);
	MoveSquare* ms = new MoveSquare();
	engine.AddKeyEvent(ms);
	engine.AddObject(csquare1, "cs1");
	irr::video::SColor back = engine.getSGLColor()->RED;
	SGLSceneSettings sceneset;
	sceneset.color = back;
	csquare1->rotateBy(20, vector2di(0,0));
	while(engine.DeviceIsRunning())
	{
		engine.BeginScene(sceneset);
		engine.DrawAll();

	}
	/*if (csquare1 != NULL)
	{
		cout << "Object did not delete" << endl;
		delete csquare1;
	}*/
	return 0;
}